package cengxubianli

type Node struct {
	Val      int
	Children []*Node
}

func levelOrder1(root *Node) [][]int {
	queue := make([][]*Node, 0)
	queue = append(queue, []*Node{root})
	ans := make([][]int, 0)
	if root == nil {
		return ans
	}
	for len(queue) > 0 {
		n := len(queue)
		cur := make([]int, 0)
		for _, v := range queue {
			if v != nil {
				for _, u := range v {
					if u.Children != nil {
						queue = append(queue, u.Children)
						cur = append(cur, u.Val)
					}
				}
			}
		}
		queue = queue[n:]
		if len(cur) > 0 {
			ans = append(ans, cur)
		}
	}
	return ans
}
